package cn.honglian.basic.util;

import cn.honglian.basic.dto.ShopAuditLogDto;
import cn.honglian.org.domain.ShopAuditLog;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Component;

import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;

@Slf4j
public class EmailUtil {




    public static void SendEMail( String from, String subject , String text, String to){
        ApplicationContext context = StringUtil.getContext();
        JavaMailSender javaMailSender = context.getBean(JavaMailSender.class);

        // 1.创建复杂邮件对象

        MimeMessage mimeMessage = javaMailSender.createMimeMessage();
        // 2.发送复杂邮件的工具类
        MimeMessageHelper helper = null;
        try {
            helper = new MimeMessageHelper(mimeMessage,true,"utf-8");
            helper.setFrom(from);
            helper.setSubject(subject);
            // 3.设置文本内容，第二个参数 true 代表是否是一个html内容
            helper.setText(text,true);
            // 4.添加附件
//        helper.addAttachment("好东西.jpg",new File("C:\\Users\\红莲天舞\\Desktop\\学习资料\\76963865_597289761016757_266002284012371968_o.jpg"));
            // 5.设置收件人
            helper.setTo(to);
            // 6.发送邮件
            javaMailSender.send(mimeMessage);
        } catch (MessagingException e) {
            log.info("发送邮件失败:{}",e);
            e.printStackTrace();
        }

    }


}
